Skip to content

fix(files_sharing): don't abort share:list when orphaned shares exist#62060

Open
Fantu wants to merge 1 commit into
nextcloud:masterfrom
M2Rbiz:fix/share-list-orphan-shares
Open

fix(files_sharing): don't abort share:list when orphaned shares exist#62060
Fantu wants to merge 1 commit into
nextcloud:masterfrom
M2Rbiz:fix/share-list-orphan-shares

Conversation

@Fantu

@Fantu Fantu commented Jul 13, 2026

Copy link
Copy Markdown

Summary

For several years I have been administering a server where 50–60 people work mainly with Nextcloud and Onlyoffice, and over the years they have created thousands of user shares.

When someone asked me to restore files from backup, in the cases involving shares between users they often could not tell me the exact origin of the shared file, and in two cases I wasted a lot of time because of that.

Since occ had no share:list command at the time, I had written an external script that generated a similar list every day, so that during a restore I could quickly find the origin of a share by looking at that list in a backup from a day when the share still existed.

Nextcloud 32 finally added share:list to occ, but unfortunately on that server (and I suppose in many other cases) it was unusable: some orphaned shares are always present, and a single one is enough to make the whole command abort.

I considered working around it by always deleting the orphaned shares first, but I don't want to lose the few cases where a restore can actually repair a share, nor risk needlessly removing shares because of temporary problems with the SMB file server or something else.

So I made this change so that the command also works when orphaned shares exist.

Note that orphaned shares are not skipped but included in the list, even though the most important piece of information (the source path) is missing and shown as empty/null. For cases like mine this still has some value: from the orphaned entries you can immediately tell whether a share with the exact name (or a similar one) mentioned by the user actually existed, and who it was shared with. This is already a small improvement over my old external script, which excluded orphaned shares, so I had to dig through several backups just to confirm that the share had existed at all and what it was called. I think keeping the orphaned entries visible where possible can be useful to others as well.

I also added unit tests to catch possible regressions; this command previously had no tests at all.

TODO

  • ...

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

`occ share:list` resolved the source node of every share without
handling NotFoundException, so a single orphaned share (e.g. the source
file was deleted from disk externally, or is pending removal by
DeleteOrphanedSharesJob) aborted the whole command with "Node for share
not found" and produced no output at all.

Catch the exception in both places that resolve the share node: orphaned
shares are now listed with a null source-path, and the --parent filter
skips them instead of crashing.

Add unit tests for the command (previously untested), covering listing
with an orphaned share present and the --parent filter with and without
--recursive.

Closes nextcloud#61949

Assisted-by: ClaudeCode:claude-fable-5
Signed-off-by: Fabio Fantoni <fabio.fantoni@m2r.biz>
@Fantu Fantu requested a review from a team as a code owner July 13, 2026 12:23
@Fantu Fantu requested review from icewind1991, leftybournes, provokateurin and salmart-dev and removed request for a team July 13, 2026 12:23
@Fantu

Fantu commented Jul 13, 2026

Copy link
Copy Markdown
Author

I have now also tested the fix on a small production server running Nextcloud 32.0.11 (patch applied manually to ListShares.php): it works as expected, the command lists everything even with orphaned shares present.

@icewind1991 thank you for adding the share:list command, is very useful.
This PR makes the command usable also when orphaned shares exist; what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: occ share:list aborts with "Node for share not found" if any orphaned share exists

1 participant